package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.entity.PurchaseList;
import com.atguigu.jxc.entity.PurchaseListGoods;
import com.atguigu.jxc.service.PurchaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Author: dongdong lau
 * @CreateTime: 2021/7/23 11:29
 * @Description: 进货单保存
 */
@RestController
@RequestMapping(value = "/purchaseListGoods")
public class PurchaseController {

    @Autowired
    private PurchaseService purchaseService;

    @RequestMapping(value = "/save")
    public ServiceVO<PurchaseListGoods> save(@RequestParam String purchaseNumber,
            PurchaseList purchaseList, String purchaseListGoodsStr){
        // 从请求体中获取purchaseNumber
        purchaseList.setPurchaseNumber(purchaseNumber);
        ServiceVO save = purchaseService.save(purchaseList, purchaseListGoodsStr);
        return save;
    }

    /**
     * 进货单列表展示
     * @param purchaseNumber
     * @param supplierId
     * @param state
     * @param sTime
     * @param eTime
     * @return
     */
    @RequestMapping("/list")
    public Map<String, Object> list(String purchaseNumber,
                                    Integer supplierId,
                                    Integer state,
                                    String sTime,
                                    String eTime){
        Map<String, Object> map = purchaseService.list(purchaseNumber, supplierId, state, sTime, eTime);
        return map;
    }

    /**
     * 查询商品信息
     * @param purchaseListId
     * @return
     */
    @RequestMapping("/goodsList")
    public Map<String, Object> getPurchaseListGoodsById(@RequestParam Integer purchaseListId){
        return purchaseService.getPurchaseListGoodsById(purchaseListId);
    }

    /**
     * 根据purchaseListId删除出货单信息
     * @param purchaseListId
     * @return
     */
    @RequestMapping("delete")
    public ServiceVO deletePurchaseListById(@RequestParam Integer purchaseListId){
        return purchaseService.deletePurchaseListById(purchaseListId);
    }


}
